<%-- 
    Document   : gest_campo.jsp
    Created on : 17-mag-2014, 14.46.22
    Author     : Marco
--%>

<%@page import="entity.Campo"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>SportingEventClub - Gestione Campi</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="CSS/BaseSite.css" />
        <link rel="stylesheet" type="text/css" href="CSS/datepickr.css"/>
        <script type="text/javascript" src="JQuery/datepickr.min.js"></script>
        <script type="text/javascript" src="JQuery/selezionaposti.js"></script>
        <link rel="shortcut icon" href= "Images/stadion-icon.png"/>
        <script>
            function checkCampi(modulo){
                var nCampo = document.getElementById("numerocampo");
                var nSpett = document.getElementById("numerospettatori");
                var sport = document.getElementById("sport");
                var terreno = document.getElementById("terreno");
                if(nCampo.value===""){
                    alert('Inserire il numero del campo');
                    return false;
                }else if(nSpett.value===""){
                    alert('Inserire il numero degli spettatori');
                    return false;
                }else if(sport.value===""){
                    alert('Selezionare uno sport praticabile nel campo');
                    return false;
                }else if(terreno.value===""){
                    alert('Selezionare il tipo di terreno del campo');
                    return false;
                }
                return true;                
            }
            
            function checkDataOra(){
                var data = document.getElementById("datepick2");
                var ora = document.getElementById("oracampo");
                if(data.value===""){
                    alert("Selezionare la data per il noleggio del campo");
                    return false;
                }
                else if(ora.value===""){
                    alert("Selezionare l'orario per in noleggio del campo");
                    return false;
                }
                return true;
            }
        </script> 
        <link rel="stylesheet" type="text/css" href="CSS/vertical-ticker.css"/>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
        <script type="text/javascript" src="JQuery/jquery.totemticker.js"></script>
        <title>SportEventClub</title>
    </head>
    <body>
        <div class="main">
            <div class="page">
                <div class="header">       
                    <div class="login">
                        <%@include file="login.jsp"%>
                    </div>
                    <div class="banner">
                    </div>
                    <div class="topmenu">
                        <%@include file="topmenu.jsp" %>
                    </div>
                </div>
                <div class="content">
                    <div class="content-in">
                        <div class="left-panel">
                            <div class="left-panel-in">
                                <% if(user == null){ %>
                                    <%@include file="erroresession.jsp"%>
                               <%}else{%>
                                    <%
                                        String op = (String) request.getAttribute("campo");
                                        if(op.equals("inserisci")){
                                    %>
                                            <h1 style="text-align: center;">Inserisci un nuovo campo</h1>
                                            <form action="GeneralController" method="post" onsubmit="return checkCampi(this);">
                                                <table id="insevento">
                                                    <tr>
                                                        <td>Numero campo: </td>
                                                        <td>&nbsp;</td>
                                                        <td><input type="text" name="numerocampo" id="numerocampo" style="text-align: center" placeholder="n°" value="" size="4"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td>Numero spettatori </td>
                                                        <td>&nbsp;</td>
                                                        <td><input type="text" name="numerospettatori" id="numerospettatori" style="text-align: center" placeholder="n°" value="" size="4"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td>Sport praticabile: </td>
                                                        <td>&nbsp;</td>
                                                        <td>
                                                            <select name="sport" id="sport">
                                                                <option value="" selected>Seleziona lo sport...</option>
                                                                <option value="basket">Basket</option>
                                                                <option value="calcetto">Calcetto</option>
                                                                <option value="tennis">Tennis</option>
                                                                <option value="pallavolo">Pallavolo</option>
                                                            </select>    
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Tipo terreno: </td>
                                                        <td>&nbsp;</td>
                                                        <td>
                                                            <select name="terreno" id="terreno">
                                                                <option value="" selected>Seleziona il terreno...</option>
                                                                <option value="erba">Erba sintetica</option>
                                                                <option value="parquet">Parquet</option>
                                                                <option value="terra">Terra</option>
                                                                <option value="linoleum">Linoleum</option>
                                                            </select>    
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Costo orario:</td>
                                                        <td>&nbsp;</td>
                                                        <td><input type="text" name="prezzo" value="" size="5"></td>
                                                    </tr>
                                                </table><br/><br>
                                                <button  class="myButton blue" type="submit" name="submit" id="btnsubmit" value="inserimentoCampo" style="margin-left: 320px;">Aggiungi campo</button>
                                            </form>
                                    <%  
                                        }else if(op.equals("inserito")){
                                    %>
                                        <h1 style="text-align: center; color: #0088ff;">Campo inserito con successo</h1><br/>
                                        <h3 style="text-align: center;"><a href="homepage.jsp">Torna alla home</a>&nbsp;&nbsp;&nbsp; oppure &nbsp;&nbsp;&nbsp;<a href="amministrazione.jsp">Torna ad amministrazione</a></h3>
                                    <%
                                        }else if(op.equals("tabellaCampi")){

                                    %>
                                        <%
                                            String operation = (String)request.getAttribute("operation");
                                            List<Campo> campi = (List<Campo>) request.getAttribute("elencocampi");
                                            if(campi.size()==0){
                                    %>
                                                <h2 style="text-align:center;">Non sono presenti campi nel database</h2>
                                    <%
                                            }else{

                                    %>
                                            <h2 style="text-align:center;">Elenco Campi:</h2>
                                                <table style="text-align: center;margin-left: 85px;;" border = \"1\" cellspacing=\"0\">
                                                    <thead><tr><td>Id campo</td><td>Numero Campo</td><td>Numero spettatori</td><td>Sport</td><td>Terreno</td><td>Costo orario</td><td>Operazione</td></tr></thead>
                                                <tbody>
                                    <%
                                                for(int i=0; i<campi.size(); i++){
                                    %>
                                                <form action="GeneralController" method="post">
                                                    <%if(i%2==0){%>
                                                        <tr class="riga_pari">
                                                    <%}else{%>
                                                        <tr class="riga_dispari">
                                                    <%}%>
                                                                <td><%=campi.get(i).getId()%></td>
                                                                <td><%=campi.get(i).getNumeroCampo()%></td>
                                                                <td><%=campi.get(i).getNumeroSpettatori()%></td>
                                                                <td><%=campi.get(i).getSport()%></td>
                                                                <td><%=campi.get(i).getTipoTerreno()%></td>
                                                                <td><%=campi.get(i).getPrezzo()%></td>
                                                                <td>
                                                                    <%if(operation==null){%>
                                                                        <button type="submit" class="myButton blue" id="btnev" name="submit" value="modificaSingoloCampo" style="text-align:center;">Modifica</button>
                                                                    <%} else if(operation.equals("campiBySport")){%>
                                                                        <button  type="submit" class="myButton blue" id="btnev" name="submit" value="prenotaSingoloCampo" style="text-align:center;">Prenota</button>                                                                    
                                                                    <%}%>
                                                                </td>
                                                        </tr>  
                                                        <input type="hidden" name="idcampo" value="<%=campi.get(i).getId()%>"/>
                                                        <input type="hidden" name="nCampo" value="<%=campi.get(i).getNumeroCampo()%>"/>
                                                        <input type="hidden" name="nSpett" value="<%=campi.get(i).getNumeroSpettatori()%>"/>
                                                        <input type="hidden" name="sport" value="<%=campi.get(i).getSport()%>"/>
                                                        <input type="hidden" name="terreno" value="<%=campi.get(i).getTipoTerreno()%>"/>
                                                        <input type="hidden" name="prezzo" value="<%=campi.get(i).getPrezzo()%>"/>
                                                    </form>
                                        <%      }

                                            }
                                        %>
                                                </tbody>
                                            </table>
                                    <%}else if(op.equals("modificaSingoloCampo")){%>
                                        <h1 style="text-align: center;">Modifica campo:</h1>
                                            <form action="GeneralController" method="post">
                                                <table id="insevento">
                                                    <tr>
                                                        <td>Numero campo: </td>
                                                        <td>&nbsp;</td>
                                                        <td><input type="text" name="numerocampo" id="numerocampo" style="text-align: center" value="<%=(String)request.getParameter("nCampo")%>" size="4"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td>Numero spettatori </td>
                                                        <td>&nbsp;</td>
                                                        <td><input type="text" name="numerospettatori" id="numerospettatori" style="text-align: center"  value="<%=request.getParameter("nSpett")%>" size="4"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td>Sport praticabile:</td>
                                                        <td></td>
                                                        <td>
                                                            <%
                                                                String sport = request.getParameter("sport");
                                                                if(sport.equals("basket")){ 
                                                            %>
                                                                <select name="sport" id="sport">
                                                                    <option value="basket" selected>Basket</option>
                                                                    <option value="calcetto">Calcetto</option>
                                                                    <option value="tennis">Tennis</option>
                                                                    <option value="pallavolo">Pallavolo</option>
                                                                </select>    
                                                            <%}else if(sport.equals("calcetto")){%>
                                                                <select name="sport" id="sport">
                                                                    <option value="basket">Basket</option>
                                                                    <option value="calcetto" selected>Calcetto</option>
                                                                    <option value="tennis">Tennis</option>
                                                                    <option value="pallavolo">Pallavolo</option>
                                                                </select>    
                                                            <%}else if(sport.equals("tennis")){%>
                                                                <select name="sport" id="sport">
                                                                    <option value="basket">Basket</option>
                                                                    <option value="calcetto">Calcetto</option>
                                                                    <option value="tennis" selected>Tennis</option>
                                                                    <option value="pallavolo">Pallavolo</option>
                                                                </select>    
                                                            <%}else{%>
                                                            <select name="sport" id="sport">
                                                                    <option value="basket">Basket</option>
                                                                    <option value="calcetto">Calcetto</option>
                                                                    <option value="tennis">Tennis</option>
                                                                    <option value="pallavolo" selected>Pallavolo</option>
                                                                </select>    
                                                            <%}%>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Tipo terreno:</td>
                                                        <td></td>
                                                        <td>
                                                         <%
                                                            String terreno = request.getParameter("terreno");
                                                            if(terreno.equals("erba sintetica")){
                                                         %>
                                                                <select name="terreno" id="terreno">
                                                                    <option value="erba" selected>Erba sintetica</option>
                                                                    <option value="parquet">Parquet</option>
                                                                    <option value="terra">Terra</option>
                                                                    <option value="linoleum">Linoleum</option>
                                                                </select>    
                                                            <%}else if(terreno.equals("parquet")){%>
                                                                <select name="terreno" id="terreno">
                                                                    <option value="erba">Erba sintetica</option>
                                                                    <option value="parquet" selected>Parquet</option>
                                                                    <option value="terra">Terra</option>
                                                                    <option value="linoleum">Linoleum</option>
                                                                </select>    
                                                            <%}else if(terreno.equals("terra")){%>
                                                                <select name="terreno" id="terreno">
                                                                    <option value="erba">Erba sintetica</option>
                                                                    <option value="parquet">Parquet</option>
                                                                    <option value="terra" selected>Terra</option>
                                                                    <option value="linoleum">Linoleum</option>
                                                                </select>    
                                                            <%}else{%>
                                                                <select name="terreno" id="terreno">
                                                                    <option value="erba">Erba sintetica</option>
                                                                    <option value="parquet">Parquet</option>
                                                                    <option value="terra">Terra</option>
                                                                    <option value="linoleum" selected>Linoleum</option>
                                                                </select>    
                                                            <%}%>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>Costo orario:</td>
                                                        <td>&nbsp;</td>
                                                        <td><input type="text" name="prezzo" value="<%=request.getParameter("prezzo")%>" size="5"></td>
                                                    </tr>
                                                </table><br/><br>
                                                <input type="hidden" name="idcampo" value="<%=request.getParameter("idcampo")%>"/>
                                                <button type="submit" name="submit" id="btnsubmit" value="updateCampo" style="margin-left: 320px;">Modifica campo</button>
                                            </form>
                                    <%  }else if(op.equals("modificaAvvenuta")){%>
                                            <h2 style="text-align: center;">Modifica avenuta con successo</h2><br/>
                                            <h4 style="text-align: center;"><a href="amministrazione.jsp">Torna ad amministrazione</a></h4>
                                    <%  }else if(op.equals("modificaNonAvvenuta")){%>
                                            <h2 style="text-align: center;">Errore nella modifica del campo, contattare l'amministratore!</h2><br/>
                                            <h4 style="text-align: center;"><a href="amministrazione.jsp">Torna ad amministrazione</a></h4>        
                                    <%  }else if(op.equals("sceglisport")){%>
                                        <form name="sceglisport" method="post" action="GeneralController" style="text-align: center;">
                                            <h1>Scegli lo sport:</h1><br/>
                                            <select name="sport" id="sport" style="height: 40px; width: 150px; font-size: 25px;">
                                                <option value="basket">Basket</option>
                                                <option value="calcetto" selected>Calcetto</option>
                                                <option value="tennis">Tennis</option>
                                                <option value="pallavolo">Pallavolo</option>
                                            </select><br/><br/><br/><br/><br/><br/>
                                            <button type="submit" name="submit" id="btnsubmit" value="avantiSport" style="margin-left: 350px;">Avanti</button>
                                        </form>
                                    <%  } else if(op.equals("sceglidata")){
                                            String nCampo = request.getParameter("nCampo");
                                            String idCampo = request.getParameter("idcampo");
                                                                         
                                    %>
                                    <h1 style='text-align: center; color: #0088ff'>Prenota campo <%=nCampo%>:</h1><br/><br/><br/>
                                    <table width="700" border="0">
                                        <tr>
                                            <td width="450px" height="400px">
                                                <%if(nCampo.equals("1")){%>
                                                    <iframe src="https://www.google.com/calendar/embed?title=Calendario%20campo%201&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;mode=WEEK&amp;height=400&amp;wkst=2&amp;hl=it&amp;bgcolor=%23FFFFFF&amp;src=21k6080cnp4qf9feicqnc79itc%40group.calendar.google.com&amp;color=%232F6309&amp;ctz=Europe%2FRome" style=" border-width:0 " width="550" height="400" frameborder="0" scrolling="no"></iframe>
                                                <%}else if(nCampo.equals("2")){%>
                                                    <iframe src="https://www.google.com/calendar/embed?title=Calendario%20campo%202&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;mode=WEEK&amp;height=400&amp;wkst=2&amp;hl=it&amp;bgcolor=%23FFFFFF&amp;src=v6qkioirqbdput1dsk59741qkk%40group.calendar.google.com&amp;color=%23875509&amp;ctz=Europe%2FRome" style=" border-width:0 " width="550" height="400" frameborder="0" scrolling="no"></iframe>                                                
                                                <%} else if(nCampo.equals("3")){%>
                                                    <iframe src="https://www.google.com/calendar/embed?title=Calendario%20campo%203&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;mode=WEEK&amp;height=400&amp;wkst=2&amp;hl=it&amp;bgcolor=%23FFFFFF&amp;src=ggndm17ol0slmu8j5egpnl8qqk%40group.calendar.google.com&amp;color=%23B1440E&amp;ctz=Europe%2FRome" style=" border-width:0 " width="550" height="400" frameborder="0" scrolling="no"></iframe>
                                                <%}else if (nCampo.equals("4")){%>
                                                    <iframe src="https://www.google.com/calendar/embed?title=Calendario%20campo%204&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;mode=WEEK&amp;height=400&amp;wkst=2&amp;hl=it&amp;bgcolor=%23FFFFFF&amp;src=v05c7t88g7153jlk4d8d97lgc8%40group.calendar.google.com&amp;color=%23B1365F&amp;ctz=Europe%2FRome" style=" border-width:0 " width="550" height="400" frameborder="0" scrolling="no"></iframe>                                                
                                                <%} else if(nCampo.equals("5")){%>
                                                    <iframe src="https://www.google.com/calendar/embed?title=Calendario%20campo%205&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;mode=WEEK&amp;height=400&amp;wkst=2&amp;hl=it&amp;bgcolor=%23FFFFFF&amp;src=ijs5ltsida7f00nmuq195pa5oo%40group.calendar.google.com&amp;color=%23333333&amp;ctz=Europe%2FRome" style=" border-width:0 " width="550" height="400" frameborder="0" scrolling="no"></iframe>
                                                <%}else if (nCampo.equals("6")){%>
                                                    <iframe src="https://www.google.com/calendar/embed?title=Calendario%20campo%206&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;mode=WEEK&amp;height=400&amp;wkst=2&amp;hl=it&amp;bgcolor=%23FFFFFF&amp;src=p9oog47uchnb6dcc7cphb2d8m4%40group.calendar.google.com&amp;color=%236B3304&amp;ctz=Europe%2FRome" style=" border-width:0 " width="550" height="400" frameborder="0" scrolling="no"></iframe>
                                                <%} else if(nCampo.equals("7")){%>
                                                    <iframe src="https://www.google.com/calendar/embed?title=Calendario%20campo%207&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;mode=WEEK&amp;height=400&amp;wkst=2&amp;hl=it&amp;bgcolor=%23FFFFFF&amp;src=jubhgk9i14no9aclgil73i3eu0%40group.calendar.google.com&amp;color=%231B887A&amp;ctz=Europe%2FRome" style=" border-width:0 " width="550" height="400" frameborder="0" scrolling="no"></iframe>
                                                <%}else if (nCampo.equals("8")){%>
                                                    <iframe src="https://www.google.com/calendar/embed?title=Calendario%20campo%208&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;mode=WEEK&amp;height=400&amp;wkst=2&amp;hl=it&amp;bgcolor=%23FFFFFF&amp;src=ocuuna7okqog7f8f8e8oqe9ljg%40group.calendar.google.com&amp;color=%23182C57&amp;ctz=Europe%2FRome" style=" border-width:0 " width="550" height="400" frameborder="0" scrolling="no"></iframe>
                                                <%} else if(nCampo.equals("9")){%>
                                                    <iframe src="https://www.google.com/calendar/embed?title=Calendario%20campo%209&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;mode=WEEK&amp;height=400&amp;wkst=2&amp;hl=it&amp;bgcolor=%23FFFFFF&amp;src=3bl92msnjr4ohmlpnnhdmgophk%40group.calendar.google.com&amp;color=%235F6B02&amp;ctz=Europe%2FRome" style=" border-width:0 " width="550" height="400" frameborder="0" scrolling="no"></iframe>
                                                <%}else if (nCampo.equals("10")){%>   
                                                    <iframe src="https://www.google.com/calendar/embed?title=Calendario%20campo%2010&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;mode=WEEK&amp;height=400&amp;wkst=2&amp;hl=it&amp;bgcolor=%23FFFFFF&amp;src=7umvpvllvcfflbvdl2kkjhfobg%40group.calendar.google.com&amp;color=%23AB8B00&amp;ctz=Europe%2FRome" style=" border-width:0 " width="550" height="400" frameborder="0" scrolling="no"></iframe>
                                                <%}%>
                                            </td>
                                            <td>
                                                <form action="GeneralController" method="post" onsubmit="return checkDataOra();">
                                                    <table width="150px" height="400px" border="0" style='text-align:center;'>
                                                        <tr>
                                                            <td><h3>Scegli la data:</h3></td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                <input type="text" id="datepick2" name="datepick2" size="10" placeholder="gg-mm-aa" style="text-align:center;">                                                  
                                                                <script type="text/javascript">
                                                                    new datepickr('datepick2', {
                                                                        'dateFormat': 'd-m-y'
                                                                    });
                                                                </script>
                                                            </td>
                                                        </tr>

                                                        <tr>
                                                            <td><h3>Scegli l'orario:</h3></td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                <select name="oracampo" id="orariocampo">
                                                                    <option value="" selected>Ora...</option>
                                                                    <option value="10:00">10:00</option>
                                                                    <option value="11:00">11:00</option>
                                                                    <option value="12:00">12:00</option>
                                                                    <option value="13:00">13:00</option>
                                                                    <option value="14:00">14:00</option>
                                                                    <option value="15:00">15:00</option>
                                                                    <option value="16:00">16:00</option>
                                                                    <option value="17:00">17:00</option>
                                                                    <option value="18:00">18:00</option>
                                                                    <option value="19:00">19:00</option>
                                                                    <option value="20:00">20:00</option>
                                                                    <option value="21:00">21:00</option>
                                                                    <option value="22:00">22:00</option>
                                                                </select>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td></td>
                                                        </tr>
                                                        <tr>
                                                            <td></td>
                                                        </tr>
                                                        <tr>
                                                            <td></td>
                                                        </tr>
                                                        <tr>
                                                            <td><button type='submit' name='submit' id='btnsubmit' value='prenotazioneCampo' style='margin-left: 0px;'>Prenota</button></td>
                                                        </tr>
                                                    </table>
                                                    <input type="hidden" name="nCampo" value="<%=nCampo%>"/>
                                                    <input type="hidden" name="idcampo" value="<%=idCampo%>"/>
                                                    <input type="hidden" name="nomeutente" value="<%=user%>"/>
                                                </form>
                                            </td>
                                        </tr>
                                    </table>
                                    <%} else if(op.equals("prenotato")){
                                            String result = (String)request.getAttribute("prenotazione");
                                            if(result.equals("avvenuta")){%>
                                                <h1 style="text-align: center; color: #0088ff;">Prenotazione avvenuta con successo</h1><br/>
                                                <h3 style="text-align: center;"><a href="homepage.jsp">Torna alla home</a>&nbsp;&nbsp;&nbsp; oppure &nbsp;&nbsp;&nbsp;<a href="amministrazione.jsp">Torna ad amministrazione</a></h3>
                                    <%      }else{%>
                                                <h1 style="text-align: center; color: #0088ff;">ERRORE: la prenotazione non è andata a buon fine!<br/>Contattare l'amministratore e riprovare</h1><br/>
                                                <h3 style="text-align: center;"><a href="homepage.jsp">Torna alla home</a>&nbsp;&nbsp;&nbsp; oppure &nbsp;&nbsp;&nbsp;<a href="amministrazione.jsp">Torna ad amministrazione</a></h3>    
                                    <%  
                                            }
                                        }
                                    %>
                                <%}%>
                            </div>
                        </div>
                        <div class="right-panel">
                            <div class="right-panel-in">
                                <jsp:include page="/GeneralController">
                                    <jsp:param name="submit" value="right-content"/>
                                    <jsp:param name="op" value="newsbox"/>
                                </jsp:include>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="footer">
                    <%@include file="footer.jsp" %> 
                </div>
            </div>
        </div> 
    </body>
</html>
